class @AdminUserEditView extends CustomView

    el: $('#content')
    
    initialize: ->
        super
        @model.bind("change", @render)
        @model.fetch()
                
    render: ->
        @GetTemplate(SiteMap.Admin.Users.EditTemplate, (compiledTemplate) =>
            $(@el).html(compiledTemplate(@model.toJSON()))
            $("#Status").combobox()
            $("#Avatar").ImageUpload()
        )
    
    events:
        "click .buttons>button.save": "save"
        "click .buttons>button.cancel": "cancel"

    save: (e) ->
        e.preventDefault()
        Loading.Start()
        Messages.WriteMessage('Saving user.')

        data = $(@el).find("form.general").serialize()

        $.post(SiteMap.Admin.Users.Edit + "?userId=" + @model.get("UserId"), data, (response) =>
            if (response.SuccessMessage? && response.SuccessMessage.length)
                Messages.WriteSuccessMessage(response.SuccessMessage);
                @Navigate(SiteMap.Admin.Users.Listing, true)
            else
                Messages.WriteErrors(response.Errors)
                Loading.Stop()
        );

    cancel: (e) ->
        e.preventDefault()
        Loading.Start()
        Messages.Clear()
        @Navigate(SiteMap.Admin.Users.Listing, true)
